<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#assign currentMenu="hotel"/>
    <#include "../common/header.ftl">
    <script src="/js/plugins/jquery-bootstrap/jquery.bootstrap.min.js"></script>

    <style type="text/css">
        .modal-body {
            max-height: 750px;
            overflow-y: auto;
        }

        .modal-body img {
            width: 100%;
        }
    </style>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-9">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">已发布酒店管理</h1>
                </div>
            </div>

            <form class="form-inline" id="searchForm" action="/hotel/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入酒店名称/商圈/交通枢纽">
                </div>

                <button class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a type="button" class="btn btn-success editBtn">
                    <span class="glyphicon glyphicon-plus"></span> 新增
                </a>

            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>序号</th>
                    <th>酒店名称</th>
                    <th>酒店图片</th>
                    <th>所在城市</th>
                    <th>所属商圈</th>
                    <th>交通枢纽</th>
                    <th>地址</th>
                    <th>联系方式</th>
                    <th>最低价格</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                <#list result.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${entity.name}</td>
                        <td><img src="${entity.coverUrl}" width="100"/></td>
                        <td>${entity.city.name}</td>
                        <td>${(entity.business.title)!}</td>
                        <td>${(entity.traffic.title)!}</td>
                        <td>${entity.address}</td>
                        <td>${entity.tel}</td>
                        <td>${entity.minPrice}</td>
                        <td>${entity.stateName}</td>
                        <td>


                            <a type="button" class="btn  btn-danger btn-xs changeState">
                                <span class="glyphicon glyphicon-ban-circle"></span> 下架

                            </a>
                            <a type="button" class="btn btn-primary btn-xs editBtn"
                               data-json='${(entity.json)!}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>

<#-- hotel模态框 -->
    <div id="inputModal" class="modal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title">酒店编辑</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" action="/hotel/saveOrUpdate.do" method="post"
                          enctype="multipart/form-data" id="editForm">
                        <input type="hidden" name="id"/>
                        <div class="form-group" >
                            <label class="col-lg-4 control-label">酒店名称：</label>
                            <div class="col-lg-6">
                                <input type="text" class="form-control" name="name"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-4 control-label">酒店图片：</label>
                            <div class="col-lg-6">
                                <img id="coverUrl" style="width: 100%"/>
                                <input type="file" class="form-control" name="img"/>
                                <input type="hidden" name="coverUrl"/>
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-lg-4 control-label">所在城市：</label>
                            <div class="col-lg-6">
                                <select class="form-control" name="city.id">
                                <#list cities as c>
                                    <option value="${c.id}">${c.name}</option>
                                </#list>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-4 control-label">所属商圈：</label>
                            <div class="col-lg-6">
                                <select class="form-control" name="business.id">
                                <#list businesses as b>
                                    <option value="${b.id}">${b.title}</option>
                                </#list>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-4 control-label">交通枢纽：</label>
                            <div class="col-lg-6">
                                <select class="form-control" name="traffic.id">
                                <#list traffics as t>
                                    <option value="${t.id}">${t.title}</option>
                                </#list>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-4 control-label">地址：</label>
                            <div class="col-lg-6">
                                <input type="text" class="form-control" name="address"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-4 control-label">联系方式：</label>
                            <div class="col-lg-6">
                                <input type="text" class="form-control" name="tel"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-4 control-label">最低价格：</label>
                            <div class="col-lg-6">
                                <input type="text" class="form-control" name="minPrice"/>
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-lg-4 control-label">状态：</label>
                            <div class="col-lg-6">
                                <select class="form-control" name="state">
                                    <option value="1">正常</option>
                                    <option value="0">禁用</option>
                                    <option value="2">推荐</option>
                                </select>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary submitBtn">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
$(function () {
    $(".editBtn").click(function () {


        $("#editForm")[0].reset();
        var json = $(this).data("json");
        console.log(json);
        if(json){
            $("#editForm input[name=id]").val(json.id);
            $("#editForm input[name=name]").val(json.name);
            $("#editForm input[name=coverUrl]").val(json.coverUrl);
            $("#coverUrl").attr("src",json.coverUrl);
            $("#editForm select[name='city.id']").val(json.cityId);
            $("#editForm select[name='business.id']").val(json.businessId);
            $("#editForm select[name='traffic.id']").val(json.trafficId);
            $("#editForm input[name=address]").val(json.address);
            $("#editForm input[name=tel]").val(json.tel);
            $("#editForm input[name=minPrice]").val(json.minPrice);
            $("#editForm select[name=state]").val(json.state);

        }
        $("#inputModal").modal("show");
    })

    $(".submitBtn").click(function () {
        $("#editForm").submit();
    })
})
</script>
</body>
</html>